package catgory;

import com.google.common.collect.Maps;
import org.apache.commons.collections4.ListUtils;
import org.assertj.core.util.Lists;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * describe:数字处理工具
 *
 * @author huxingjie
 * @date 2019/04/01
 * @since 3.6
 */
public class NumberUtil {

    public static String getPercent(double number1, double number2) {
        double percent = number1 / number2;
        //获取格式化对象
        NumberFormat nt = NumberFormat.getPercentInstance();
        //设置百分数精确度2即保留两位小数
        nt.setMinimumFractionDigits(2);
        //最后格式化并输出
        return nt.format(percent);
    }

    public static String formate(Double d) {
        //获取格式化对象
        NumberFormat nt = NumberFormat.getNumberInstance();
        //设置百分数精确度2即保留两位小数
        nt.setMaximumFractionDigits(10);
        //最后格式化并输出
        return nt.format(d);
    }

    public static void main(String[] args) {
        VideoResourceTypeEnum videoResourceTypeEnum = VideoResourceTypeEnum.fromType(null);
        Long l4 = 0L;
        System.out.println(l4.equals(1L));
        System.out.println(Double.valueOf("1.1122268888888112226888888811222688888881122268888888"));
        System.out.println(formate(Double.valueOf("1.1122268888888")));
        Map<String, List<String>> map = Maps.newHashMap();
        List<String> l1 = Lists.newArrayList("1", "2", "3");
        List<String> l2 = Lists.newArrayList("1", "2", "4");
        System.out.println("ListUtils.subtract(l1, l2) "+ListUtils.subtract(l1, l2));
        List<String> l3 = Lists.newArrayList("5");
//        IntSummaryStatistics collect = l1.stream().collect(Collectors.summarizingInt(value -> value));
        map.put("1", l1);
        map.put("2", l2);
        map.put("3", l3);
        Integer s = map.values().stream().mapToInt(l -> l.size()).sum();
//        long s = collect.stream().collect(Collectors.summarizingInt(v->v)).getSum();
        long c = map.values().stream().mapToLong(List::size).sum();
        List<String> stringList = map.values().stream().flatMap(l -> l.stream()).collect(Collectors.toList());
        System.out.println(stringList);
        Iterator i = l1.iterator();
        int n = 0;
        while (i.hasNext()) {
            i.next();
            System.out.println(n++);
        }
        String path = "bm://batch-video-process/4441/output/task-74dfd3a1-4589-4827-897f-2a68181fdfb8_1.json.gz";
        String c1 = "bm://";
        String s1 = path.substring(c1.length());
        System.out.println(path.startsWith(c1));
    }
}
    